package com.feign.controller;

import com.api.bean.User;
import com.feign.service.RefactorHelloService;
import com.feign.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 许小宝 on 2017/9/20.
 */
@RestController
public class ConsumerController {
    @Autowired
    RefactorHelloService refactorHelloService;

    @Autowired
    UserService userService;

    @GetMapping(value = "/feign-consumer")
    public String helloConsumer() {
       return refactorHelloService.hello();
    }

    @GetMapping("/feign-consumer2")
    public String helloConsumer(@RequestParam("name") String name) {
        return refactorHelloService.hello(name);
    }

    @GetMapping("/feign-consumer3")
    public User helloConsumer(String name, Integer age) {
        name = "xxb";
        age = 25;
        return refactorHelloService.hello(name, age);
    }

    @GetMapping("/feign-consumer4")
    public String helloConsumer(User user) {
        if (user == null) user = new User();
        user.setName("xxb");
        user.setAge(25);

        return refactorHelloService.hello(user);
    }

    @GetMapping("/feign/user")
    public String getUserName() {
        return userService.getUserName();
    }
}
